package com.thinkpadteam.edugra.fragmentmakan;
import java.util.ArrayList;
import com.thinkpadteam.edugra.R;
import com.thinkpadteam.edugra.fragment.LessonConclution;
import com.thinkpadteam.edugra.game.GameMencocokkan;
import com.thinkpadteam.edugra.gridview.ImageItem;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class LayoutMakan extends Fragment {
	private ImageView imgBenda;
	int mCurrentPage;
	ArrayList<ImageItem> imageItems, videoItems;
	MediaPlayer player;
	Boolean statusPlayer=false;
		
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		/** Getting the arguments to the Bundle object */
		Bundle data = getArguments();
		
		/** Getting integer data of the key current_page from the bundle */
		mCurrentPage = data.getInt("current_page", 0);
				
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.sliderlayout, container, false);
		imgBenda = (ImageView) rootView.findViewById(R.id.imgBenda);	

		
		imageItems = new ArrayList<ImageItem>();
		String called_from = getActivity().getIntent().getStringExtra("materi");		

		TypedArray imgs =null;
		if (called_from.equalsIgnoreCase("makan")){
			imgs= getResources().obtainTypedArray(R.array.img_makan_ids);
		}else if (called_from.equalsIgnoreCase("mandi")){
			imgs= getResources().obtainTypedArray(R.array.img_mandi_ids);
		}else{
			imgs= getResources().obtainTypedArray(R.array.img_sekolah_ids);
		}

		Log.d("jum array", called_from+" "+ imgs.length());
		Log.d("img array", called_from+" "+ imgs.getString(1));
		imgBenda.setBackgroundDrawable(imgs.getDrawable(mCurrentPage-1));
		
		Toast.makeText(getActivity(), "PAGE : "+mCurrentPage, Toast.LENGTH_SHORT).show();
				
//		videoItems = new ArrayList<ImageItem>();
//		final TypedArray videos = getResources().obtainTypedArray(R.array.video_makan_ids);
		final TypedArray videos = getResources().obtainTypedArray(R.array.video_makan_ids);
		Log.d("video array", "zz "+ videos.getString(1));
//		ImageButton btnKesimpulan = (ImageButton) rootView.findViewById(R.id.kesimpulan);
//		btnKesimpulan.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				Resources resource = getResources();
//				Intent intent = new Intent(getActivity(), LessonConclution.class);
////				intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.thinkpadteam.edugra/"+videos.getString(1)));
//				String vid=videos.getString(mCurrentPage);
////				int vid= getActivity().getResources().getIdentifier(videos.getString(1), "raw", "com.thinkpadteam.edugra");
//				
//				String uriextra="android.resource://com.thinkpadteam.edugra/"+videos.getString(1);
//				Uri uriex = Uri.parse("android.resource://com.thinkpadteam.edugra/"+videos.getString(1));
//				intent.putExtra("urivideo", uriextra.toString());
//				
////				String uriextra="android.resource://com.thinkpadteam.edugra/"+R.raw.videomakan;
//				startActivity(intent);	
//			}
//		});
		return rootView;	
	}
		

//	  @Override
//	  public void onDestroy() {
//	    if(null!=player){
//	   player.release();
//	    }
//	    super.onDestroy();
//	  }	

}
